package com.zlp.exception.entity;

/**
 * @author: ZouLiPing
 * @date: 2018/10/10 17:55
 * @description: Response响应结构
 */

import com.fasterxml.jackson.annotation.JsonInclude;
import com.zlp.exception.constants.Constants;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private T data;

    private int status;

    private String msg = "请求成功";

    public Response() {
        this.status = Constants.SUCCESS;
    }

    public Response(int status, String msg) {
        this();
        this.status = status;
        this.msg = msg;
    }

    public Response(int status, String msg, T data) {
        this();
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public Response(T data) {
        this();
        this.data = data;
    }

    public static Response ok() {
        return new Response(Constants.SUCCESS, "success");
    }

    public static Response ok(String msg) {
        return new Response(Constants.SUCCESS, msg);
    }

    public static <T> Response<T> ok(T data) {
        return new Response(Constants.SUCCESS, "success", data);
    }

    public static Response error() {
        return new Response(500, "error");
    }

    public static Response error(String msg) {
        return new Response(500, msg);
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
